package com.tools.developer.app;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.tools.developer.DataBaseActivity;
import com.tools.developer.R;
import com.tools.developer.SignatureActivity;

public class AppDetailActivity extends ListActivity implements
		OnItemClickListener {

	public static final String PKG_NAME = "pkg_name";
	private String mPkgName;
	private AppModel mApp;
	private String[] mItems = { SINATURE, OPEN_DATABASE };
	private static final String SINATURE = "show sinature";
	private static final String OPEN_DATABASE = "open database";
	public static final String APP_MODEL = "app_model";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_app_detail);

		if (getIntent() != null) {
			AppModel app = getIntent().getParcelableExtra(APP_MODEL);
			if (app != null) {
				mApp = app;
				mPkgName = mApp.packageName;
				((TextView) findViewById(R.id.txt)).setText(String
						.valueOf(mApp.memUsage));
			}

		}
		setListAdapter(new ArrayAdapter<String>(AppDetailActivity.this,
				android.R.layout.simple_list_item_1, mItems));
		getListView().setOnItemClickListener(this);
	}

	@Override
	protected void onResume() {
		super.onResume();
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		if (position < mItems.length) {
			Intent intent = null;
			if (SINATURE.equalsIgnoreCase(mItems[position])) {
				intent = new Intent(AppDetailActivity.this,
						SignatureActivity.class);
			} else if (OPEN_DATABASE.equalsIgnoreCase(mItems[position])) {
				intent = new Intent(AppDetailActivity.this,
						DataBaseActivity.class);
			}
			if (intent != null) {
				intent.putExtra(PKG_NAME, mPkgName);
				this.startActivity(intent);
			}
		}

	}
}
